package order

import (
	"context"
	order2 "goods-rpc/internal/server/order"
	"goods-rpc/proto/order"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

type OrderRpcService struct {
	order.UnimplementedOrderServer
}

func (l *OrderRpcService) OrderList(ctx context.Context, req *order.OrderListReq) (*order.OrderListResp, error) {
	takeList, err := order2.TakeList()
	if err != nil {
		return nil, err
	}
	return &order.OrderListResp{List: takeList}, nil
}

func (l *OrderRpcService) OrderAdd(ctx context.Context, req *order.OrderAddReq) (*order.OrderAddResp, error) {
	if req.AddInfo.OrderNo == "" {
		return nil, status.Error(codes.Unimplemented, "用户名不能为空")
	}
	if req.AddInfo.OrderStatus == 0 {
		return nil, status.Error(codes.Unimplemented, "购买数量不能为空")

	}
	if req.AddInfo.CreatedAt == "" {
		return nil, status.Error(codes.Unimplemented, "商品属性不能为空")

	}
	if req.AddInfo.OrderNum == 0 {
		return nil, status.Error(codes.Unimplemented, "商品售价不能为空")

	}
	if req.AddInfo.OrderCount == 0 {
		return nil, status.Error(codes.Unimplemented, "商品店铺不能为空")

	}
	if req.AddInfo.UserId == 0 {
		return nil, status.Error(codes.Unimplemented, "商品图片不能为空")

	}
	if req.AddInfo.GoodsId == 0 {
		return nil, status.Error(codes.Unimplemented, "商品图片不能为空")
	}

	takeAdd, err := order2.TakeAdd()
	if err != nil {
		return nil, err
	}

	return &order.OrderAddResp{Info: takeAdd}, nil
}
